<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>详情页</title>
    <!-- css样式 -->
    <link rel="stylesheet" href="css/xiangqing.css" />

    <link rel="stylesheet" href="css/reset.css" />

    <!-- jquery -->

    <script src="js/jquery.js"></script>
  </head>
  <body>
    <div class="box">
      <!-- <div class="l">
        <img src="img/home1.jpg" alt="" />
      </div> -->
      <div id="zoomBox">
        <div id="midArea">
          <img src="img/10068.jpg" alt="" />

          <div id="zoom"></div>

          <div id="bigArea">
            <img src="img/10068.jpg" alt="" class="bigImg" />
          </div>
        </div>
        <div id="smallArea">
          <img src="img/10069.jpg" alt="" />
          <img src="img/10070.jpg" alt="" />
          <img src="img/10071.jpg" alt="" />
          <img src="img/10068.jpg" alt="" />
        </div>
      </div>
      <div class="r">
        <h2>KBNE</h2>
        <p>秋冬新款斜纹翻领简约气质毛呢大衣外套女</p>
        <ul class="color">
          <li>灰色</li>
        </ul>
        <span class="price"><i>￥489</i>元</span>
        <div class="btn" onclick="button()">加入购物车</div>
      </div>
    </div>
    <script>
      function $(id) {
        return document.getElementById(id);
      }
      class Zoom {
        constructor() {
          this.zoomBox = $("zoomBox");
          this.midArea = $("midArea");
          this.midImg = this.midArea.children[0];
          this.zoom = $("zoom");
          this.bigArea = $("bigArea");
          this.bigImg = this.bigArea.children[0];
          this.smallArea = $("smallArea");
          this.smallImg = this.smallArea.children;
          this.show();
        }
        show() {
          this.midArea.onmouseover = () => {
            this.zoom.style.display = "block";
            this.bigArea.style.display = "block";
          };
          this.midArea.onmouseout = () => {
            this.zoom.style.display = "none";
            this.bigArea.style.display = "none";
          };
          this.midArea.onmousemove = (e) => {
            let evt = e || event;
            let x =
              evt.pageX - this.zoomBox.offsetLeft - this.zoom.offsetWidth / 2;
            let y =
              evt.pageY - this.zoomBox.offsetTop - this.zoom.offsetHeight / 2;

            if (x <= 0) {
              x = 0;
            }
            if (x >= this.midArea.offsetWidth - this.zoom.offsetWidth) {
              x = this.midArea.offsetWidth - this.zoom.offsetWidth;
            }
            if (y <= 0) {
              y = 0;
            }
            if (y >= this.midArea.offsetHeight - this.zoom.offsetHeight) {
              y = this.midArea.offsetHeight - this.zoom.offsetHeight;
            }
            this.zoom.style.left = x + "px";
            this.zoom.style.top = y + "px";

            this.bigImg.style.left =
              (-this.bigArea.offsetWidth / this.zoom.offsetWidth) * x + "px";
            this.bigImg.style.top =
              (-this.bigArea.offsetHeight / this.zoom.offsetHeight) * y + "px";
          };
          for (let i = 0; i < this.smallImg.length; i++) {
            this.smallImg[i].onmouseover = () => {
              this.midImg.src = this.bigImg.src = this.smallImg[i].src;
            };
          }
        }
      }
      new Zoom();

      function button() {
        window.location.href = "shopping.html";
      }
    </script>
  </body>
</html>
